from datetime import datetime
import random

GRID = 0.5      # 0.5% 网格
BASE = 10000    # 1 万底仓

def do_t_signal(code: str, price: float) -> dict:
    """返回 {'side': 'B/S/None', 'qty': 100, 'reason': 'grid'}"""
    # 用前 1 条作为“网格中枢”，非交易时段随机中枢
    center = price * (1 - random.uniform(-0.01, 0.01))
    upper = center * (1 + GRID / 100)
    lower = center * (1 - GRID / 100)
    if price >= upper:
        return {'side': 'S', 'qty': 100, 'reason': 'grid_high'}
    if price <= lower:
        return {'side': 'B', 'qty': 100, 'reason': 'grid_low'}
    return {'side': 'None'}
